<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'营业额期号'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['month']){
		$params['end_time']=strtotime($_RQ['month']);
		$return['params']['month']=$_RQ['month'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('upfeelog',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array(
			'tip'=>'按周期，自动结算活动营业额。分红比例按分销等级中的设置来处理！',
			'data'=>'list','edit'=>false,'del_one'=>true,'delall'=>false,'list'=>array(
			array('name'=>'month','title'=>'周期号','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'red_type'),
			array('name'=>'totalfee','title'=>'营业额','type'=>'string'),
			array('name'=>'money','title'=>'参与分红总奖金','type'=>'string'),
			array('name'=>'user_num','title'=>'参与分红人数','type'=>'string'),		
		),'batch'=>array(
			array('type'=>'post','url'=>'/levelfee/updata/','title'=>'一键发放上月分红'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'month','title'=>'周期号'),
		),
	);
	$return['htmls']=$htmls;
	$return['red_type']=$this->red_type;
	exi($return);
}
if($_RQ['op']=='updata'){
	$this->model('model')->add_upfee();
	exi('一键发放成功！');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_newganfee_level',array('id'=>$id));	
	}
	if(!$id){
		exi('默认等级不能删除！','error');
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_newganfee_level',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}